package com.woniu.cms.auth.core.controller;


import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.woniu.cms.auth.core.entity.Company;
import com.woniu.cms.auth.core.service.ICompanyService;
import com.woniu.common.api.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author lilili
 * @since 2022-09-16
 */
@RestController
@RequestMapping("/company")
@Api(tags="公司控制器")
public class CompanyController {
    @Resource
    private ICompanyService companyService;

    /**
     * 查找所有
     *
     * @return {@link Result}<{@link List}<{@link Company}>>
     */
    @GetMapping
    @ApiOperation("获取所有公司")
    public Result<List<Company>> findAll(){
        List<Company> list = companyService.list();
        return Result.common(list);
    }

    /**
     * 提交
     *
     * @param name 公司名称
     * @return {@link Result}<{@link Object}>
     */
    @PostMapping("/{name}")
    @ApiOperation("添加公司")
    public Result<Object> commit(@PathVariable("name") String name){
        Company company = new Company().setCompanyName(name);
        boolean save = companyService.save(company);
        return Result.common(save);
    }

    /**
     * 更新
     *
     * @param company 公司
     * @return {@link Result}<{@link Object}>
     */
    @PutMapping
    @ApiOperation("更新公司")
    public Result<Object> update(@RequestBody Company company){
        boolean b = companyService.updateById(company);
        return Result.common(b);
    }

    /**
     * 删除
     *
     * @param id id
     * @return {@link Result}<{@link Object}>
     */
    @DeleteMapping("/{id}")
    @ApiOperation("删除公司")
    public Result<Object> delete(@PathVariable("id") Integer id){
        boolean b = companyService.removeById(id);
        return Result.common(b);
    }
}

